package configs

import (
	"context"
	"github.com/micro/go-micro/v2/util/log"
	"github.com/olivere/elastic/v7"
	"sync"
)

var (
	EsClient *elastic.Client
	once     sync.Once
	err      error
	Ctx      context.Context
)

func InitEs() {
	once.Do(func() {
		// 创建一个空的上下文
		Ctx = context.Background()
		// 创建一个
		EsClient, err = elastic.NewClient(
			elastic.SetURL(EsConf.Hosts...),
		)
		if err != nil {
			log.Error("服务器启动失败，es客户端创建失败")
		}
	})
}
